package com.meetingshow.common.base.actions;

import org.apache.struts2.ServletActionContext;

import com.meetingshow.common.Global;
import com.meetingshow.privilege.uiservice.model.UserVO;
import com.opensymphony.xwork2.ActionSupport;

public abstract class BaseAction extends ActionSupport {

    /**
     * 
     */
    private static final long serialVersionUID = 3485757358049586140L;
    
    protected String buildErrorJson(String errorCode, String errorMsg) {
        StringBuilder sBuilder = new StringBuilder();
        sBuilder.append("{\"errorCode\":").append("\"").append(errorCode).append("\",")
            .append("\"errorMsg\":").append("\"").append(errorMsg).append("\"}");
        
        return sBuilder.toString();
    }
    
    protected String buildSuccJson() {
        StringBuilder sBuilder = new StringBuilder();
        sBuilder.append("{\"success\":").append("\"1\"}");
        return sBuilder.toString();
    }
    
    /**
     * get the user have logged in.
     * @return
     */
    protected UserVO getLoginUser() {
        UserVO userVO = (UserVO) ServletActionContext.getRequest()
            .getSession().getAttribute(Global.SESSION_ATTR_USER);
        
        return userVO;
    }
}
